package com.example.rocketmqtest.consumer;

import cn.hutool.core.date.DateUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.common.message.MessageExt;
import org.apache.rocketmq.spring.annotation.ConsumeMode;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.stereotype.Component;

@Component
@RocketMQMessageListener(topic = "delay-test-topic", consumerGroup = "delay-test-topic-group",
        consumeMode = ConsumeMode.ORDERLY)
@Slf4j
public class DelayTestConsumer implements RocketMQListener<MessageExt> {

    @Override
    public void onMessage(MessageExt message) {
        log.info("收到消息 time:{},queueId:{},content:{},bornTimestamp:{},storeTimestamp:{},delayTimeLevel={},delayTimeSec:{}",
                DateUtil.date(), message.getQueueId(), new String(message.getBody()),
                DateUtil.date(message.getBornTimestamp()),
                DateUtil.date(message.getStoreTimestamp()),
                message.getDelayTimeLevel(),
                message.getDelayTimeSec());
    }

}
